package com.example.hello;

import com.example.hello.client.NavbarButton.BootstrapNavbarButtonRpc;
import com.example.hello.client.NavbarButton.BootstrapNavbarButtonState;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.ui.AbstractComponent;

public class BootstrapNavbarButton extends AbstractComponent {

    private BootstrapNavbarButtonRpc rpc = new BootstrapNavbarButtonRpc() {
        public void click(MouseEventDetails details) {
            fireEvent(new BootstrapEvent(BootstrapNavbarButton.this));
        }
    };

    public BootstrapNavbarButton() {
        this("", BootstrapButton.Type.DEFAULT, BootstrapButton.Size.DEFAULT);
    }

    public BootstrapNavbarButton(String caption, BootstrapButton.Size size) {
        this(caption, BootstrapButton.Type.DEFAULT, size);
    }

    public BootstrapNavbarButton(String caption, BootstrapButton.Type type) {
        this(caption, type, BootstrapButton.Size.DEFAULT);
    }

    public BootstrapNavbarButton(String caption, BootstrapButton.Type type, BootstrapButton.Size size) {
        setText(caption);
        setSize(size);
        setType(type);

        setImmediate(true);

        registerRpc(rpc);
    }

    public BootstrapNavbarButton(String caption) {
        this(caption, BootstrapButton.Size.DEFAULT);
    }

    public BootstrapNavbarButton(BootstrapButton.Size size) {
        this("", size);
    }

    public BootstrapNavbarButton(BootstrapButton.Type type) {
        this("", type);
    }

    @Override
    protected BootstrapNavbarButtonState getState() {
        return (BootstrapNavbarButtonState) super.getState();
    }

    public BootstrapButton.Size getSize() {
        return BootstrapButton.Size.valueOf(getState().getSize());
    }

    public BootstrapButton.Type getType() {
        return BootstrapButton.Type.valueOf(getState().getType());
    }

    public String getText() {
        return getState().getText();
    }

    public boolean isEnabled() {
        return getState().isButtonEnabled();
    }

    public boolean isToggle() {
        return getState().isToggle();
    }

    public void setSize(BootstrapButton.Size size) {
        getState().setSize(size.toString());
    }

    public void setType(BootstrapButton.Type size) {
        getState().setType(size.toString());
    }

    public void setText(String text) {
        getState().setText(text);
    }

    public void setEnabled(boolean enabled) {
        getState().setButtonEnabled(enabled);
    }

    public void setToggle(boolean toggle) {
        getState().setToggle(toggle);
    }

}